#include <iostream>
#include <pthread.h>
#include <unistd.h>
#include <future>


void* calculate(void* args)
{
    auto fut = (std::future<int>*)args;
    printf("thread waits to calculate...\n");
    int val = fut->get();
    printf("get value: %d\n", val);
    return NULL;
}

int main()
{
    std::promise<int> prom;
    std::future<int> fut = prom.get_future();

    pthread_t thread;
    pthread_create(&thread, NULL, calculate, &fut);

    sleep(1);
    prom.set_value(10);

    pthread_join(thread, NULL);

    return 0;
}